\input{style.tex}

%%% Begin document
\begin{document}
\newmdtheoremenv [ %
	outerlinewidth = 2pt,%
	roundcorner = 10pt,%
	leftmargin = 40,%
	rightmargin = 40 ,%
	backgroundcolor = yellow!30,%
	outerlinecolor = blue!70!black,%
	innertopmargin = \topskip,%
	splittopskip = \topskip,%
	ntheorem = true,%
 ] { theorem } { Theorem } % [ section ]
\maketitle
\thispagestyle{fancy} 			% Enabling the custom headers/footers for the first page 
% The first character should be within \initial{}
\initial{Q}\textbf{uadpod - quadrupedal walking robot or four legged walking robot - is a mechanical construction using 4~legs to move at slow speed. This project demonstrates utilization of various crawling gaits to achieve synchronized movement of the robot. Each of the tested gaits is statically balanced, the dynamically balanced gaits are outside the possibilities of this project. The mechanical construction uses 3\,mm plywood and low budget 9\,gram servos. The electronics is fitted on a single board having 2~conducting layers. Design further uses Atmel Mega168, servo shield, IR receiver and 2~independent power sources.}

\section{Mechanical Construction}\label{chapter:mechanics} % <<<
The quadpod is a robot having the smallest possible number of legs that allows to use statically balanced walking pattern. Statically stable walking pattern is generally very slow, usually used by insect to crawl. The walking cycle is however stable in any moment of the cycle and therefore very useful for analysis and study. The statically stable walking pattern requires that 3 legs are resting on the supporting surface and just one leg may be lifted at time. Additionally, the centre of gravity (CoG) of the robot must reside inside the virtual triangle formed by the foot of legs resting on the walking surface.

\subsection{Mechanics of Crawlers}\label{chapter:crawlers} % <<<
The designed robot is capable of statically balanced walking pattern only. It has neither necessary mechanical construction nor suitable systems of actuators to achieve dynamically balanced movement. The used electronics does not have enough potential to calculate the parameters of dynamically balanced movement in real time either. Therefore the further description is reduced to statically balanced walking pattern only. The details of the statically balanced walking pattern follows. 

\paragraph{Locomotion}
of legged robots is based on lifting and placing legs in a coordinated manner. This is called a gait. Gait is usually cyclic in the sense that the same sequence of lifting and placing the legs is repeated. A complete cycle of leg movements, where all the legs have been lifted and placed exactly once, is called a stride, and the time duration of one stride is called the cycle time.

\vskip 0.25cm
\begin{tabular}{>{\columncolor[gray]{0.8}[0.8\tabcolsep]\bfseries}p{7,0cm}}
	\emph{Duty factor ($\beta$)}: The fraction of the duration of the stride for which a foot is on the ground (in the support phase).
\end{tabular}
\vskip 0.25cm

\noindent
The cycle time is normalized, begins at time 0 and cycle end at time 1. Next important parameter is called duty factor. The duty factor $\beta_i$ for leg \emph{i} is the fraction of the cycle time for which the foot is in ground contact, so the duty factor is a number between 0 and 1. 

\vskip 0.25cm
\begin{tabular}{>{\columncolor[gray]{0.8}[0.8\tabcolsep]\bfseries}p{7,0cm}}
	\emph{Relative phase} ($\varphi_i$): The time elapsed from the setting down of a chosen reference foot until the foot of leg \emph{i} is set down, given as the fraction of the \emph{cycle time}.
\end{tabular}
\vskip 0.25cm

\noindent
The relative phase of leg \emph{i} is the time elapsed from the setting down of an arbitrarily chosen reference foot until the foot of leg \emph{i} is set down, given as the fraction of the cycle time as explained in the gray box. The convention used here is that the left front leg is number 1, right front leg is number 2, right hind leg is number 3, and left hind leg is number 4, as depicted in figure~\ref{fig:crab}, figure~\ref{fig:frog} respectively. The gait event sequence can now be specified using the duty factors and the relative phases, where the first event, and the start of the stride, is chosen as the event when the reference leg is set down.  \\

\begin{figure}[h]
\centering\includegraphics[width=0.27\textwidth]{support_area-xy.png}
\caption[b]{The CoG is withing the support area, which is defined by the foot of legs being in support.}
\label{fig:support_area}
\end{figure}

\noindent
In a statically stable gait, the vertical projection of the center of gravity (CoG) onto a horizontal plane, is kept within the support area at all times as shown in the figure~\ref{fig:support_area}. The support area can be described as the minimum convex polygon in a horizontal plane, with its vertices formed by the tips of the legs being in support. This description does not take into account moment of inertia and other dynamic properties of the system. It assumes zero mass of the legs as well. While these simplification are helpful when calculating the motion commands it might on the other end result in errors and instabilities in the resulting kinematics. Therefore is important to include \emph{stability margin} in the characteristics of the system. The higher stability margin the less effect of adopted simplifications. The stability margin is defined as the shortest distance from the vertical projection of the CoG of the vehicle onto a horizontal plane, to the boundary of the support area. It is defined as positive if the center of gravity is within the support polygon and negative otherwise. Negative values of stability margin cannot result in statically balanced crawl. The robot tips over due to the effect of gravity. Various strategies are available that increases the stability margin. This projects discuss \emph{swaying} and \emph{tilting} as some of the strategies.  \\
\\
\noindent
This section established the nomenclature required for further description of the walking pattern of the robot. Most of the theoretical foundation originates in the work \cite{sveden}. Interesting and complementary information were sourced in the works \cite{malaysia}, \cite{japan} respectively. 

\paragraph{Gait} variations were subject to test in this project. Basically, two geometrical configurations were used. First, a {\bfseries crab-like geometry}. The details of the geometry are depicted in the figure~\ref{fig:crab}. 

\begin{figure}[h]
\centering\includegraphics[width=0.27\textwidth]{crab-xy.png}
\caption[b]{Crab-like geometry of the legs. The leg numbering starts from left front and continues clockwise along the body.}
\label{fig:crab}
\end{figure}

\begin{figure}[h]
\centering\includegraphics[width=0.27\textwidth]{frog-xy.png}
\caption[b]{Frog or Lizard like geometry of the legs.}
\label{fig:frog}
\end{figure}

\noindent
This geometry shows that the mid of a stride is put on the line connecting the shoulder joints of both front legs, hind legs respectively. This geometry brings relatively small support area. On the other end {\bfseries titling} is more effective compared with other geometries as a strategy to increase the stability margin.\\
\\
\noindent
{\bfseries Frog / Lizard} like geometrical configuration brings larger support area though the stability margin is exactly the same compared to \emph{crab} like configuration. The mid of a stride is set on a connecting line between left front and right hind leg, as shows in figure \ref{fig:frog}. This configuration is less sensitive to the \emph{titling}. The tilting input must be much larger to achieve reasonable shifting of CoG. This configuration is however more suitable for emulated {\bfseries lizard-like gait}, where the CoG gets shifted by the swaying motion of the body.

\paragraph{Basic Crawl} is a gait with $\beta$=0.75. This is the basic crawling pattern that utilizes the minimum possible \emph{duty factor} allowed for statically balanced gait. Any value bellow this level would mean that a dynamic stability must be included in the gait, because just two legs are supporting the construction for defined fraction of a cycle. The \emph{duty factor} $\beta$=0.75 means that the robot is supported by three leg at each moment, one leg is always lifted and changing its positions. Basic crawl - using the nomenclature defined if chapter \ref{chapter:crawlers} - can be described as follows:

\begin{equation}
	\varphi_1=0\quad\varphi_2=0.5\quad\varphi_3=\beta\quad\varphi_4=\beta-0.5
	\label{equ:beta_075}
\end{equation}

\noindent
This gait was tested with both the \emph{crab} and \emph{frog} like geometry. It has been combined in both cases with tilting mechanism in oder to achieve higher positive values of stability margin.

\begin{figure}[h]
\centering\includegraphics[width=0.46\textwidth]{lizard-step-1a.png}
\caption[b]{The position of the CoG in standard walking pattern. The drawing represents the situation where the leg 1 gets placed on the surface and leg 3 just gets lifted ($\varphi_1=0,\,\varphi_3=\beta$). The stability margin is zero.}
\label{fig:lizard-step-1}
\end{figure}

\paragraph{Tilting} is a strategy helping to achieve higher positive values of stability margin. This strategy is tilting the body of the robot for specific relative phase of a stride where the stability margin approaches zero. The minimal stability margin occurs short before the leg 1 or leg 3 lifts as visible in figure \ref{fig:lizard-c-step-1}. Expressed in the model the conditions occur at:

\begin{eqnarray}
	\varphi_1=0,\,\varphi_3=\beta
	\label{equ:stability_margin_0} \\
	\varphi_2=0,\,\varphi_4=\beta 
	\label{equ:stability_margin_1}
\end{eqnarray}

\noindent
Conditions described in equations \ref{equ:stability_margin_0} and \ref{equ:stability_margin_1} generates zero stability margin as the CoG projected in the support area is exactly on the connection line between leg~2 and~4 resting on the support area. By extending the leg 3 and simultaneously retracting the leg 1 the robot tilts forward-left, virtually shifting the projected CoG deeper inside the support area, short before the leg~3 gets lifted into non-supportive position. In other word the distance increases between projected CoG and the edge of the support area shaped by the connection between legs 2 and 4. The absolute value of this distance depends on the height of the robot and size of the support area. Small titling movement generates larger shift of CoG for smaller support area and vice versa, more tilting must be added to achieve same shift of CoG in the case of larger support area. The same situation occur for conditions captured in equation \ref{equ:stability_margin_1} as well.

\paragraph{Swaying} is another strategy of increase the stability margin. Reptiles are a good example of well articulated swaying. Lizards clearly bend the body and shift its head and tail in order to place the CoG before a stride is taken.
\\
%\begin{figure}[h]
%\centering\includegraphics[width=0.49\textwidth]{lizard.png}
%\caption[b]{Emulating the swaying of the lizard's body. The legs does not follow the straight line but a specially constructed trajectory shown in this figure. The position of the legs at the beginning of the cycle is indicated by the circles.}
%\label{fig:lizard}
%\end{figure}

\noindent
This robot is having a rigid body construction, the only joins and actuators are placed in the legs. Therefore the swaying pattern must be simulated by changing the projection of the centre of mass of robot onto the walking plane. This in effect results in distorting the trajectory of each step within the stride. The trajectory is under normal circumstances straight. The emulated lizard-like walking pattern results in a trajectory shown in the figure \ref{fig:lizard-c-step-1}, \ref{fig:stalking} respectively. The first mentioned swaying model is not fully statically stable. The CoG is clearly outside the support area for two phases of the step. More specifically the static balance is not achieved shortly before the phase 1\footnote{End of phase 1 is the situation where the leg No.1 is lifted but it is shortly before it gets placed back on the support plane} and 3 end. 

\begin{figure}[h]
\centering\includegraphics[width=0.49\textwidth]{lizard-c-step-1a.png}
\caption[b]{The position of the CoG in lizard walking pattern. It corresponds the situation where the leg 1 gets placed on the surface and leg 3 just gets lifted. The symbol $\left(A\right)$ stands for the stability margin.}
\label{fig:lizard-c-step-1}
\end{figure}

\noindent
This is compensated by ``tilt'' function and by the dynamics of the movement. The robot has certain mass and thus momentum, which is used here to achieve semi-stable walking pattern. \\
\\
\noindent
The second referred model, shown in the picture \ref{fig:stalking}, compensates fthe problem described in the first swaying model and thus it brings the complete static stability for any relative phase of a stride. The penalty is slowing down the walking itself by including two section where the robot is supported by all 4 legs and is shifting its CoG only. This happens in phase 1, 3 respectively. Both are divided into \emph{(a)} and \emph{(b)} sections. While the \emph{(a)} is the ``leg shifting'' phase, the \emph{(b)} is the ``CoG shifting'' phase, where all legs are supporting the body. 

\begin{figure}[h]
\centering\includegraphics[width=0.49\textwidth]{lizard-step-2a.png}
\caption[b]{The position of the CoG in advanced swaying walking pattern. The green outlined support area is valid for the situation where the leg No.1 gets moved in its non-duty part of cycle, while the red color is used to outline the support area when the leg no.3 travels through its non-duty cycle. The symbol $\left(A\right)$ stands for the stability margin.}
\label{fig:stalking}
\end{figure}

\noindent
The phases are outlined for all legs in the drawing~\ref{fig:stalking} in small letters next to the turquoise trajectory of a step. The schema can be used for forward movement only. The trajectories of legs must be flipped (mirrored) along the longitudinal axis for reverse movement. The change in the direction cannot happen at any arbitrary phase of a stride. It only can happen when the trajectory of the step crosses the trajectory of the linear step. That is satisfied for $\varphi=0.25$ and $\varphi=0.75$ only. \\


\noindent
The figures \ref{fig:lizard-c-step-1} and \ref{fig:stalking} demonstrate the effect of the swaying pattern. The color code in the first figure uses black color of the body of the robot, the CoG clearly indicated in the middle. The turquoise color shows the step trajectory. The red triangle shows the support area at the beginning of the cycle, just after the leg~3 got lifted and the robot is supported by legs 1,2~and~4 only. The drawing~\ref{fig:lizard-c-step-1} documents the negative stability margin occuring short before the phase 1 and 3 end, which may result in tipping the whole robot\footnote{The length of the stride in the drawing corresponds with 98\,mm, which is unrealistically long stride given the mechanical construction of legs and size of the body, distances between shoulder pivot respectively. This stride is just demonstrative in oder to visualize the effect of swaying more clear. In reality the mechanical constraints allow the stride 72\,mm at maximum.}. \\ 
\\
\noindent
The lizard-like movement the trajectory of a stride is specific for each leg as shown in the figures \ref{fig:lizard-c-step-1} and \ref{fig:stalking}. The trajectory of step is depicted in cyan color. The magenta color shows the linear trajectory of foots having outlined segment for $\varphi$ at positions 0=1, 0.25, 0.50 and 0.75. The drawing is set for the same cycle of the stride as the figure \ref{fig:lizard-step-1}. The CoG is clearly moved much deeper inside the triangle of the support area, depicted in red color again. \\
\\
\noindent
Swaying is increasing the stability margin considerably and is well suited strategy to achieve statically stable crawling pattern for this robot. 

\paragraph{Advanced Crawling} is the last tested strategy in the project. Advanced crawling step is an artificial construct that increases the $\beta$ to the value as high as 0.83. The larger duty factor helps to increase the minimal positive value of the stability margin. \\   

\begin{figure}[h]
\centering\includegraphics[width=0.46\textwidth]{83-step-1.png}
\caption[b]{The position of the CoG in advanced crawling pattern. The drawing represents the situation at the beginning of the cycle, where the leg~1 is already supporting the robot and leg~3 gets just lifted. ($\varphi_1=0,\,\varphi_3=\beta$).}
\label{fig:83-step-1}
\end{figure}

\noindent
The situation depicted in the figure \ref{fig:83-step-1} corresponds with the situation captured in the figure \ref{fig:lizard-step-1}. One can see that the stability margin is a positive number in the case of the figure \ref{fig:83-step-1}, while the standard walking pattern delivers zero value of stability margin (figure \ref{fig:lizard-step-1}). The presented figure demonstrates the advantage of the gait denoted as ``$\beta=0.83$''. \\
\\
\noindent
The schema of this gait is however more complicated compared to the basic walking pattern. It is still based on the sequence 1-3-2-4, though it utilizes a model of non-equally long segments within the whole cycle. The details are discussed later in next chapter.

% >>>
\subsection{Kinematics of a Crawler}\label{chapter:kinematics} % <<<
Kinematics is the study of the geometry of a mechanical system, where the motion of the system can be described in terms of the velocity and acceleration of all its components. The components can be connected through different types of joints, which limit how the components can move relative to each other. The interconnection of the components implies that the motion of the components relative to each other is constrained. A kinematic motion of the mechanism is determined by specifying all the generalized coordinates as function of time, and thereby generating a curve for the motion of all points in the mechanism. The coordinates have to be given relative to a frame, usually a Cartesian coordinate system $\mathfrak{R}^3$, that is fixed relative to the walking plane, also known as walking frame or earth frame. Symbol \emph{fW} denotes the walking frame in the text and is depicted in the figure~\ref{fig:geometry}. \\

\begin{figure}[h]
\centering\includegraphics[width=0.46\textwidth]{geometry.png}
\caption[b]{The position of the CoG is the projection of robot's CoM onto the walking plane. The walking plane is denoted as \emph{fW} known as ``walking frame'', the orientation of the robot's body denotes \emph{fB}, known as ``body frame''. Each leg has its own ``servo frame'', \emph{fS}. The feets of leg are actually positioned withing the servo frames.}
\label{fig:geometry}
\end{figure}

\noindent
As explained in detail in source \cite{sveden} is the motion of a single component through three dimensional space $\mathfrak{R}^3$ has a geometric degree of freedom of six and can be described with a set of six generalized coordinates. Three coordinates are needed to define the position of an index point of the component, and three coordinates to define its orientation. First of all we define the frames and fixed points for this construction. The example in the figure~\ref{fig:geometry} shows the CoM, CoB respectively as the chosen fixed point for the body frame \emph{fB}. The projection of the CoM of the robot into the walking frame \emph{fW} is the base index point for the walking frame. The projection is done for idle state of the robot, having all legs in neutral position, supporting the robot. The next frame is the servo frame \emph{fS}. The index point of the servo frame is the shoulder joint of the leg. Therefore we have 4 servo frames. The relationship among the frames can be established by chain of affine rotation matrices. We can determine position of each foot by using this system of chained matrices.\\
\\
\noindent
By applying the described schema onto the mechanical construction of the robot the kinematics is calculated as follows. First, we establish the relationship between the fixed points of walking frame and body frame. This relationship is depicted in the drawing~\ref{fig:geometry} by vector $\vec{\mathcal{H}}$. The radial distance between the index points of \emph{fW} and \emph{fB} is the length of $\|\vec{\mathcal{H}}\|$. Technically, the length of this vector is the base height of the robot's body over the walking frame, known as $h_{z}^{0}$. Further we need polar angle and azimuthal angle to determine the position of index point of robot's body. It is convenient to use projection of the CoM onto $\left[x,z\right]$ and describe it by polar angle $\theta_{(xz)}$ accompanied by the projection into $\left[y,z\right]$, which yields polar angle $\theta_{(yz)}$. This transformation simplifies the rotation and eliminates the need for azimuthal angle. \\

\begin{eqnarray}
	M_{(xy)} =   
	\begin{bmatrix}
		cos(\theta_{(xy)}) & -sin(\theta_{(xy)}) & 0 \\
		sin(\theta_{(xy)}) & cos(\theta_{(xy)}) & 0 \\
		0 & 0 & 1
	\end{bmatrix} 
	\label{equ:yaw} \\
	M_{(xz)} =   
	\begin{bmatrix}
		cos(\theta_{(xz)}) & 0 & -sin(\theta_{(xz)}) \\
		0 & 1 & 0 \\
		sin(\theta_{(xz)}) & 0 & cos(\theta_{(xz)}) 
	\end{bmatrix} 
	\label{equ:roll} \\
	M_{(yz)} =   
	\begin{bmatrix}
		1 & 0 & 0 \\
		0 & cos(\theta_{(yz)}) & -sin(\theta_{(yz)}) \\
		0 & sin(\theta_{(yz)}) & cos(\theta_{(yz)}) 
	\end{bmatrix} 
	\label{equ:pitch} \\
	\vec{\mathcal{V}}_{fB} = \vec{\mathcal{V}}_{fW} M_{(xy)} M_{(xz)} M_{(yz)}
\end{eqnarray}

\noindent
We construct the vector $\vec{\mathcal{H}}=\left[0,0,h_{z}^{0}\right]$, where the coordinate $h_{z}^{0}$ is the length of the vector - $\|\vec{\mathcal{H}}\|$. The vector gets rotated by $M_{(xz)}$ (equation~\ref{equ:roll}) and $M_{(yz)}$ (equation~\ref{equ:pitch}). The coordinates \emph{x} and \emph{y} are interesting in this step, the coordinate \emph{z} is neglected. The calculated coordinates \emph{x,y} defines the ``sway'' function in the movement of the robot. In the next phase we calculate the relationship between the index points of body frame and servo frames. The index point of body frame is CoM. The index point of servo frame is shoulder joint. The robot frame has a rigid construction, therefore both \emph{x,y} coordinates are constant. The only relevant output of this rotation is then change in \emph{z} coordinates, combining the effect of function ``roll'' and ``pitch''. So again, we take vector $\left[x,0,0\right]$ and rotate it for ``roll'' angle using the matrix shown in equation $M_{(xz)}$~(\ref{equ:roll}). Following that we take vector $\left[0,y,0\right]$ rotate for the ``pitch'' angle using the matrix from equation $M_{(yz)}$~(\ref{equ:pitch}). The resulting coordinate \emph{z} is sum of both calculation. In the next step we determine the effect of ``yaw'' function on the robot.  This function affects coordinates \emph{x,y} only. Generally, the ``yaw''can be calculated for index point in the walking frame or for the index point of servo frames projected into walking frame. The input for the ``yaw'' function is always vector $\left[0,y,0\right]$, where the coordinate \emph{y} varies based on the gait style input. However the origin of \emph{y} is irrelevant for outlined procedure and will be discussed in next section. We determine 4 tuples $\left[0,y_{i},0\right]$ where the \emph{y} is different for all 4 legs, as described in the chapter about the mechanic of the robot. The 4 vectors gets rotated for the ``yaw'' angle using the matrix $M_{(xy)}$ given in equation~(\ref{equ:yaw}). Again, ``yaw'' function rotates the robot in plane $\left[x,y\right]$, therefore we can discard the coordinate \emph{x} in the last rotation.  The last step combines the results of all the preceding steps. Function ``yaw'' contributes to $\left[x,y\right]$ while both functions ``pitch'' and ``roll'' impacts the coordinate \emph{z} only. We use combined vectors for the final step, which is the rotation in the $\left[x,y\right]$ plane. This rotation expresses the relationship between the body frame and servo frames. The rotation takes the cumulated vector describing the index points of shoulder frame plus the yaw input for each leg. This vector is first translated for $\left[x,y\right]$ coordinates given by vector $\vec{\mathcal{L}}=\left[x,y\right]$, whose length corresponds with the physical construction of a leg.
The foot of a leg has an initial position, a ``sweet'' point. It is an ideal position of foot within an action radius of a leg. The value of translation in direction \emph{x} and \emph{y} is given by the topology of the construction and can be either crab-like or frog-like as described in the figure~\ref{fig:crab}, figure~\ref{fig:frog} respectively. Using the 4 leg vectors, translating them for input given by geometry we finally rotate the vectors to receive the coordinates for all feet in a phase of a step. This procedure is repeated for every change to ``yaw'', ``pitch'', ``roll'' input as well as for change in \emph{y} coordinate of a step.   

\begin{figure}[h]
\centering\includegraphics[width=0.32\textwidth]{roll_sway.png}
\caption[b]{The project into the plane z-x. The figure \emph{(a)} is the base position, figure \emph{(b)} is infuence of the ``roll'' and \emph{(c)} is the effect of including the ``swaying''}
\label{fig:roll}
\end{figure}

\noindent
The drawing in the figure~\ref{fig:roll}(a) shows the basic position of the robot, with no movement function applied. The CoM corresponds with CoG and the normalized length of gravity vector is 1. The gravity vectors of shoulder pivots are all the same, having the same normalized length as the gravity vector of CoG. The figure~\ref{fig:roll}(b) shows effect of the roll input. The robot rolls to the right, the properties of gravity vector for CoG do not change but the gravity vectors of shoulder pivots will change. The normalized length of the vectors in the interval $\left(0,+x)\right)$ will be $<1$ while the normalized length of gravity vectors from interval $\left(-x,0\right)$ will be $>1$. The same is true for pitch input, the only change is that coordinate \emph{x} is swapped for coordinate \emph{y}. The last section is the section (c) in the figure~\ref{fig:roll}. This sction shows the effect of roll combined with swaying input. In this case the properties of the gravity vector for CoG will differ as well, in the contrary to the section (b). The normalized length of the new gravity vector of CoM will be $<1$, while the properties of gravity vectors for the shoulder pivots will remain the same. 

\paragraph{Applied Kinematics} The kinematics solution for this project adopted several simplifications. First of all, the firmware does not implement roll, pitch and sway properties in a generalized way through rotational matrices. The only generalized function remains then ``yaw''. The effect of roll, pitch and sway is pre-calculated and stored in tabulated form in the robot's firmware. By adopting this limitations the movement of the robot can be described by a vector $\vec{\mathcal{U}}=\left[x,y,z\right]$, which is placed inside an Cartesian system $\mathfrak{R}^3$ described by $\left[x,y,z\right]$ as well. In other word, six coordinates are required to describe the movement. First we establish the origin on the vector $\vec{\mathcal{U}}$ in the Cartesian system $\mathfrak{R}^3$ and three other coordinates describes its orientation in the same space. 
\\
\\
\begin{minipage}{0.02\linewidth}
	\rule{2pt}{65pt}
\end{minipage} \hspace{0pt}
%
\begin{minipage}{0.89\linewidth}
%\begin{flushleft}
\vspace{5pt}
	\begin{abstract} 
Let us set the base position of the robot's body in Cartesian space $\mathfrak{R}^3$. The \emph{y} characterizes the forward/backward movement, \emph{x} sideways direction and \emph{z} defines up/down movement of the robot. 
	\end{abstract}
%\end{flushleft}
\end{minipage}
\vspace{20pt}		% Add some vertical spacing to seperate the abstract from the rest of the article
\\
\noindent
The crawler has a certain height given by the physical dimensions of the construction. The vector $\vec{\mathcal{U}}$ defines the characteristics of the movement relative to the projection of the robot's CoG into walking plane. \\
\\
\noindent
The element \emph{z} is always considered zero and the motion of the robot is therefore calculated for the plane $\left[x,y\right]$ only. This simplification is acceptable for this kind of hobby project. The robot cannot climb and walk side-slopped plane. The change in the \emph{z} axis is required for tilting and lifting legs and those operations are controlled by adding constant values of \emph{z} to complete the position vector of each leg. The input is controlled by a tabulated values specific for each leg and phase.\\
\\
\noindent
The simplified kinematics approach chosen for this project follows this schema:

\begin{enumerate}
\item We assume the robot crawls forward. It means that we identify the new point \emph{y}, which is different than the current value of \emph{y}. The change in \emph{y}-coordinate defines crawling forwards, backwards respectively. New position can be expressed as a vector $\vec{\mathcal{U}}=\left[x,y,z\right]$. Let us call it a motion vector of the whole robot. Let us establish that the motion vector is relative to the CoG and is having the coordinates \emph{x}=\emph{z}=0. In other words, the motion vector described the movement of the CoG on the plane $\left[x,y\right]$. This simplification will allow to use motion vector for robot expressed in polar coordinates by its length $\|\vec{\mathcal{U}}\|=\Delta$ and angle $\phi$. The angle direction is clockwise. Zero angle $\phi=0$ means that the robot crawls straight forwards, $\angle\phi=45^{\circ}$ means the robot crawl sideways left-forwards and so on. The angle $\phi$ is the ``yaw'' input. The resulting length of step $\Delta$ is kept constant for further movement, which is an unnecessary simplification of the solution. That can be easy overcome in next phases of the project. The $\angle\phi$ is variable and thus the only result of this step. 

\item The motion vector for all fourth legs $\vec{\mathcal{P}}_i$ of the robot is derived from the robot's motion vector  $\vec{\mathcal{U}}$. Generally, each vector $\vec{\mathcal{P}}_i$ is having the same direction $\phi$ as $\vec{\mathcal{U}}$ but the length is different for all of them $\|\vec{\mathcal{P}}_1\|\,\neq\|\vec{\mathcal{P}}_2\|\,\neq\|\vec{\mathcal{P}}_3\|\,\neq\|\vec{\mathcal{P}}_4\|$. This is because of the gait schema 1-3-2-4, as described in chapter \ref{chapter:crawlers}.  First the rules valid for basic walking pattern:   

\begin{align} 
	\begin{split}
	x &= 0 \\
	y &= \left\{ \begin{array}{l}
		+\Delta / 2 \\
		-\Delta / 2 \end{array} \right \\
	z &= 0 
	\label{equ:generic_direction} 
	\end{split}					
\end{align}

where the variable $\Delta$ is the length of the step (see figure \ref{fig:lizard-step-1} for reference) determined in the previous step. The \emph{x,z} are set to zero initially. The only variable for the basic calculation is \emph{y}, which can take value from the interval $y\in\left( -\rfrac{\Delta}{2};+\rfrac{\Delta}{2}\right)$. The exact value for the phases of the individual legs is determined based on the equation \ref{equ:beta_075}. As already mentioned, this schema is frequently referred as 1-3-2-4. \\
\\
Each cycle is split into 4 segment, 3 are duty segments (cycle phases) and one is not. Each segment is further divided into 3 subsections. This fine segmenting helps to achieve smooth stride. \\

\begin{table}[h]
\caption{Relative phase for $\beta=0.75$. The gray cells indicate the non-duty part of the cycle. Dark gray is full non-duty segment, light shade of gray means that a change from duty to non-duty (or vice-versa) is just happening at the given index.}
\label{tab:step}
\centering
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{l*{12}{p{5pt}}}
	\hline 
	& 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \\
	\hline \hline
	$\varphi_1$ & \cellcolor[gray]{0.85} $\frac{9}{9}$ & \cellcolor[gray]{0.7} $\frac{6}{9}$ & \cellcolor[gray]{0.7} $\frac{3}{9}$ & \cellcolor[gray]{0.85} $\frac{0}{9}$ & $\frac{1}{9}$ & $\frac{2}{9}$ & $\frac{3}{9}$ & $\frac{4}{9}$ & $\frac{5}{9}$ & $\frac{6}{9}$ & $\frac{7}{9}$ & $\frac{8}{9}$ \\
		\hline
		$\varphi_2$ & $\frac{3}{9}$ & $\frac{4}{9}$ & $\frac{5}{9}$ & $\frac{6}{9}$ & $\frac{7}{9}$ & $\frac{8}{9}$ & \cellcolor[gray]{0.85} $\frac{9}{9}$ & \cellcolor[gray]{0.7} $\frac{6}{9}$ & \cellcolor[gray]{0.7} $\frac{3}{9}$ & \cellcolor[gray]{0.85} $\frac{0}{9}$ & $\frac{1}{9}$ & $\frac{2}{9}$ \\
		\hline
		$\varphi_3$ & $\frac{6}{9}$ & $\frac{7}{9}$ & $\frac{8}{9}$ & \cellcolor[gray]{0.85} $\frac{9}{9}$ & \cellcolor[gray]{0.7} $\frac{6}{9}$ & \cellcolor[gray]{0.7} $\frac{3}{9}$ & \cellcolor[gray]{0.85} $\frac{0}{9}$ & $\frac{1}{9}$ & $\frac{2}{9}$ & $\frac{3}{9}$ & $\frac{4}{9}$ & $\frac{5}{9}$ \\
		\hline
		$\varphi_4$ & \cellcolor[gray]{0.85} $\frac{0}{9}$ & $\frac{1}{9}$ & $\frac{2}{9}$ & $\frac{3}{9}$ & $\frac{4}{9}$ & $\frac{5}{9}$ & $\frac{6}{9}$ & $\frac{7}{9}$ & $\frac{8}{9}$ & \cellcolor[gray]{0.85} $\frac{9}{9}$ & \cellcolor[gray]{0.7} $\frac{6}{9}$ & \cellcolor[gray]{0.7} $\frac{3}{9}$ \\
	\end{tabular}
\end{table}
\renewcommand{\arraystretch}{1.0}

\noindent
The table \ref{tab:step} describes the normalized phases of cycle for the basic gait, having $\beta=0.75$. Variable \emph{k} is established as the cycle index. The cycle index ranges 0~through~11, which is the product of having 4 main segments further divided into 3 sub-segments. The reference leg is chosen leg~4. The cycle index is set to zero at the moment when the leg No.4 is placed on the surface in accordance with the theory described in chapter 1.1. The cycle begins. \\

\noindent
Corresponding equation to determine the element \emph{y} takes form:

	\begin{equation}
		y_{i,k} = \frac{\Delta}{2} - \varphi_{i,k}\,\Delta
	\end{equation}

\noindent
A little more complicated is the swaying pattern, which additionally utilizes changes in the \emph{x} axis to imitate swaying motion:

\begin{align} 
	\begin{split}
	x &= \left\{ \begin{array}{l}
		+\Delta / 3 \\
		-\Delta / 3 \end{array} \right \\
	y &= \left\{ \begin{array}{l}
		+\Delta / 2 \\
		-\Delta / 2 \end{array} \right \\
	z &= 0 
	\label{equ:lizard_direction} 
	\end{split}					
\end{align}

The \emph{y} coordinate in the vector can again take values from the interval $y\in\left( -\rfrac{\Delta}{2};+\rfrac{\Delta}{2}\right)$. Additionally, the \emph{x} is not zero but takes values from the interval $x\in\left( -\rfrac{\Delta}{3};+\rfrac{\Delta}{3}\right)$. The exact values are coordinated for each phase of the cycle between both \emph{x} and \emph{y}. This schema is as well referred as 1-3-2-4 and the segmenting of a cycle is the same as the basic crawl. The timing table for vector coordinate \emph{y} is exactly the same as the table \ref{tab:step}. The coordinate \emph{x} is synchronized with the table \ref{tab:step} and takes form captured in the table \ref{tab:sway}.

\begin{table}[h]
\caption{Relative phase for swaying component $\xi$ at $\beta=0.75$.}
\label{tab:sway}
\centering
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{l*{12}{p{5pt}}}
	\hline 
	& 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \\
	\hline \hline
	$\xi_{k}$ & $\frac{0}{9}$ & $\frac{3}{9}$ & $\frac{6}{9}$ & $\frac{9}{9}$ & $\frac{6}{9}$ & $\frac{3}{9}$ & $\frac{0}{9}$ & $\frac{-3}{9}$ & $\frac{-6}{9}$ & $\frac{-9}{9}$ & $\frac{-6}{9}$ & $\frac{-3}{9}$  \\
	\hline
	\end{tabular}
\end{table}
\renewcommand{\arraystretch}{1.0}

\noindent
and the corresponding look up equation:

	\begin{equation}
		x_{k} = \frac{\Delta}{3}\,\xi_{k}
		\label{equ:sway}
	\end{equation}

\begin{table}[h]
	\caption{Relative phase for $\beta=0.75$, advanced swaying pattern. Legend is identical with table\ref{tab:step}}
\label{tab:advstep}
\centering
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{l*{18}{p{6pt}}}
	\hline 
	& 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 \\
	\hline \hline
$\varphi_1$ & \cellcolor[gray]{0.85} $\frac{9}{9}$ & \cellcolor[gray]{0.7} $\frac{6}{9}$ & \cellcolor[gray]{0.7} $\frac{3}{9}$ & \cellcolor[gray]{0.85} $\frac{0}{9}$ & $\frac{0}{9}$ & $\frac{0}{9}$ & $\frac{0}{9}$ & $\frac{1}{9}$ & $\frac{2}{9}$ & $\frac{3}{9}$ & $\frac{4}{9}$ & $\frac{5}{9}$ & $\frac{6}{9}$ & $\frac{6}{9}$ & $\frac{6}{9}$ & $\frac{6}{9}$ & $\frac{7}{9}$ & $\frac{8}{9}$ \\
		\hline
$\varphi_2$ & $\frac{3}{9}$ & $\frac{4}{9}$ & $\frac{5}{9}$ & $\frac{6}{9}$ & $\frac{6}{9}$ & $\frac{6}{9}$ & $\frac{6}{9}$ & $\frac{7}{9}$ & $\frac{8}{9}$ & \cellcolor[gray]{0.7} $\frac{9}{9}$ & \cellcolor[gray]{0.85} $\frac{6}{9}$ & \cellcolor[gray]{0.7} $\frac{3}{9}$ & \cellcolor[gray]{0.85} $\frac{0}{9}$ & $\frac{0}{9}$ & $\frac{0}{9}$ & $\frac{0}{9}$ & $\frac{1}{9}$ & $\frac{2}{9}$ \\
		\hline
$\varphi_3$ & $\frac{6}{9}$ & $\frac{7}{9}$ & $\frac{8}{9}$ & $\frac{9}{9}$ & $\frac{9}{9}$ & $\frac{9}{9}$ & \cellcolor[gray]{0.85} $\frac{9}{9}$ & \cellcolor[gray]{0.7} $\frac{6}{9}$ & \cellcolor[gray]{0.7} $\frac{3}{9}$ & \cellcolor[gray]{0.85} $\frac{0}{9}$ & $\frac{1}{9}$ & $\frac{2}{9}$ & $\frac{3}{9}$ & $\frac{3}{9}$ & $\frac{3}{9}$ & $\frac{3}{9}$ & $\frac{4}{9}$ & $\frac{5}{9}$ \\
		\hline
$\varphi_4$ & \cellcolor[gray]{0.85} $\frac{0}{9}$ & $\frac{1}{9}$ & $\frac{2}{9}$ & $\frac{3}{9}$ & $\frac{3}{9}$ & $\frac{3}{9}$ & $\frac{3}{9}$ & $\frac{4}{9}$ & $\frac{5}{9}$ & $\frac{6}{9}$ & $\frac{7}{9}$ & $\frac{8}{9}$ & $\frac{9}{9}$ & $\frac{9}{9}$ & $\frac{9}{9}$ & \cellcolor[gray]{0.85} $\frac{9}{9}$ & \cellcolor[gray]{0.7} $\frac{6}{9}$ & \cellcolor[gray]{0.7} $\frac{3}{9}$
	\end{tabular}
\end{table}
\renewcommand{\arraystretch}{1.0}

\begin{table}[h]
\caption{Relative phase for advanced swaying component $\xi$ at $\beta=0.75$.}
\label{tab:advsway}
\centering
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{l*{18}{p{6pt}}}
	\hline 
	& 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 \\
	\hline \hline
	$\xi_{k}$ & $\frac{0}{9}$ & $\frac{-3}{9}$ & $\frac{-6}{9}$ & $\frac{-9}{9}$ & $\frac{-3}{9}$ & $\frac{3}{9}$ & $\frac{9}{9}$ & $\frac{6}{9}$ & $\frac{3}{9}$ & $\frac{0}{9}$ & $\frac{3}{9}$ & $\frac{6}{9}$ & $\frac{9}{9}$ & $\frac{3}{9}$ & $\frac{-3}{9}$ & $\frac{-9}{9}$ & $\frac{-6}{9}$ & $\frac{-3}{9}$ \\
	\hline
	\end{tabular}
\end{table}
\renewcommand{\arraystretch}{1.0}

\noindent
The swaying is the same for all the legs within the cycle, therefore a one-row-table is sufficient to describe the dependency. The resulting motion model for each leg looks different (see~figure~\ref{fig:lizard-c-step-1}) because of the phase shift among the legs. The more complicated swaying pattern, displayed in the drawing~\ref{fig:stalking}, requires 18 indices in the ``relative phase'' table. It must be again synchronized between \emph{x} and \emph{y} input, therefore both tables must consists of 18 stops. Tables~\ref{tab:advstep} and \ref{tab:advsway} documents the extended lookup tables for advanced swaying documented in the drawing~(\ref{fig:stalking}).\\   

\item The leg-vectors produced in last steps are rotated for the angle $\phi$ established in the first step. That is the ``yaw'' function and determine the direction of movement function in the walking frame. As a result we yield the rotated motion vectors $\vec{\mathcal{R}}_i$, where \emph{i} is the index of the leg. 

\begin{align}
	\vec{\mathcal{R}}_i = \vec{\mathcal{P}}_i \times  
	\begin{bmatrix}
		cos(\phi) & -sin(\phi) & 0 \\
		sin(\phi) & cos(\phi) & 0 \\
		0 & 0 & 1
	\end{bmatrix}
\end{align}

\item The rotated motion vector $\vec{\mathcal{R}}_i$ for all legs are still related to body frame of the robot. In this step we apply the transformation to translate the motion vector into specific servo frames. This operation involves translation and rotation. The index point for servo frame is the shoulder joint. The distance between a foot and shoulder joint is the translation constant. The translation follows the geometry from figure \ref{fig:crab} and \ref{fig:frog}. The absolute value of the translation \\ 

\begin{flushright}
\vspace{-20pt}
\begin{minipage}[c]{0.60\linewidth}
\noindent
further depends on the physical dimensions of robot's legs. The frog geometry takes $\vec{\mathcal{D}}_i=\left[\delta_x^i,\delta_y^i,\delta_z^i\right]=\left[\pm36,\pm36,+51\right]$. The crab like geometry takes translation $\vec{\mathcal{D}}_i=\left[\delta_x^i,\delta_y^i,\delta_z^i\right]=\left[\pm51,0,+51\right]$. The constant shift in the coordinate \emph{z} is given by the physical construction of the leg and sets the height of the CoG above the walking plane. The figure \ref{fig:height} demonstrates the effect of the \emph{z} coordinate on the walking geometry.

\end{minipage} \hspace{0pt}
\end{flushright}

\noindent
The coordinate \emph{z} does not include any input from either ``sway'' or ``tilt'' component yet.\\

\begin{table}[h]
\caption{signs for legs.}
\label{tab:signs}
\centering
%\renewcommand{\arraystretch}{1.5}
\begin{tabular}{l|*{4}{p{5pt}}}
	\hline
	\multicolumn{4}{r}{Leg} \\
	\cline{2-5} 
	& 1 & 2 & 3 & 4 \\
	\hline \hline
	x & $-$ & + & + & $-$ \\
	y & + & + & $-$ & $-$ \\
	\hline
	\end{tabular}
\end{table}
%\renewcommand{\arraystretch}{1.0}

\noindent
The sign in the translation vectors is important and determines in which quadrant the translation takes place. See the drawing in the figure \ref{fig:servo_mounts} for better orientation regarding the quadrants. The unit used is millimeter. \\
\\
\noindent
Using the figure \ref{fig:servo_mounts} and figures \ref{fig:frog}, \ref{fig:crab} the table \ref{tab:signs} is constructed. The table indicates, in which direction the translation of foot relative to shoulder pivot takes place.

\begin{figure}[h]
\centering\includegraphics[width=0.44\textwidth]{height.png}
\caption[b]{The height of the CoG above the walking plane. The gray shadows show both minimal and maximal height. The optimal position is depicted in the full color schema. The height of the robot's CoG is controlled by a constant value - $h_0^z=51\,mm$.}
\label{fig:height}
\end{figure}

Resulting translation vectors $\vec{\mathcal{D}}_i$ for frog/lizard like geometry produced by using the input from table \ref{tab:signs}:
\begin{eqnarray}
\left[\delta_x^1,\delta_y^1,\delta_z^1\right]=\left[-36,+36,+51\right]\,mm \\
\left[\delta_x^2,\delta_y^2,\delta_z^2\right]=\left[+36,+36,+51\right]\,mm \\ 
\left[\delta_x^3,\delta_y^3,\delta_z^3\right]=\left[+36,-36,+51\right]\,mm \\
\left[\delta_x^4,\delta_y^4,\delta_z^4\right]=\left[-36,-36,+51\right]\,mm 
\end{eqnarray}

Similarly for the crab geometry. The resulting vector $\vec{\mathcal{R}}_i^{\mathcal{D}}$ is processed further in next step. 

\item In oder to complete the transposition into servo frame the rotation is performed. This rotation reflects the fact that the orthogonal system of each leg (servo frame \emph{fS}) is rotated in relation to the base orthogonal system describing the robot's body (body frame \emph{fB}). \\ 

\begin{figure}[h]
\centering\includegraphics[width=0.44\textwidth]{servo_mounting.png}
\caption[b]{Mount point of legs on the robot's body. The schema helps to determine the sign for displacement of the motion vectors and further additional rotation specific for shoulder pivot actuators.}
\label{fig:servo_mounts}
\end{figure}

\noindent
In other words the figures \ref{fig:geometry} and \ref{fig:servo_mounts} shows the relationship between the servo frames, body frame and walking frame. The relationship can be described by single angle only, named $\psi_i$. Based on the figure \ref{fig:servo_mounts} we can determine the angle for each leg:

%\begin{eqnarray}
\begin{align} 
	\begin{split}
	\psi_1&=45\degr \\
	\psi_2&=315\degr \\
	\psi_3&=225\degr \\
	\psi_4&=135\degr 
	\end{split}
\end{align} 
%\end{eqnarray}

The rotation operation takes form of again the affine matrix. The \emph{z} is constant, just elements \emph{x,z} are subject to rotate.

\begin{align}
	\vec{\mathcal{T}}_i = \vec{\mathcal{R}}_i^{\mathcal{D}} \times
	\begin{bmatrix}
		cos(\psi_i) & -sin(\psi_i) & 0 \\
		sin(\psi_i) & cos(\psi_i) & 0 \\
		0 & 0 & 1
	\end{bmatrix}
\end{align}

The resulting vector $\vec{\mathcal{T}}_i$ includes direction angle $\phi$, displacement contribution $\vec{\mathcal{D}}_i$ and last not least the ``mount point angle $\psi_i$'', which describes the relationship between orthogonal system of the robot's body and the plane of a leg. 

\item Until now we ignored the effect of ``roll'' and  ``pitch'' functions. This simplified approach is simulating the input of those two functions though a set of tabulated values. The tabulated values also mix in the effect of change in \emph{z}-coordinated required to lift and place feet on walking plane. Both lifting/placing and tilting affects in this simplification coordinate \emph{z} only. The project uses tabulated values again to implement leg lifting. The table \ref{tab:ztable} was used to capture the lifting and placing the leg.

\begin{table}[h]
\caption{Complementary data for Relative phase for $\beta=0.75$. This table defines the change in the z-axis for each leg.}
\label{tab:ztable}
\centering
%\renewcommand{\arraystretch}{1.5}
\begin{tabular}{l|*{12}{p{5pt}}}
	\hline 
	& 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \\
	\hline \hline
	1 & 0 & 9 & 9 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
		\hline
	2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 9 & 9 & 0 & 0 & 0 \\
		\hline
	3 & 0 & 0 & 0 & 0 & 9 & 9 & 0 & 0 & 0 & 0 & 0 & 0 \\
		\hline
	4 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 9 & 9 \\
		\hline
	\end{tabular}
\end{table}
%\renewcommand{\arraystretch}{1.0}

\noindent
The \emph{z} element can also include the titling input. This input can be integrated inside the complementary z-table and the resulting table takes forms shown in the table \ref{tab:ztable_titling}.

\begin{table}[h]
\caption{Complementary data for Relative phase for $\beta=0.75$. This table defines the change in the z-axis for each leg including titling effect.}
\label{tab:ztable_titling}
\centering
%\renewcommand{\arraystretch}{1.5}
\begin{tabular}{l|p{11pt}*{2}{p{5pt}}p{11pt}*{2}{p{5pt}}p{11pt}*{2}{p{5pt}}p{11pt}*{2}{p{5pt}}}
	\hline 
	& 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \\
	\hline \hline
	1 & $-12$ & 9 & 9 & 9 & 12 & 12 & 0 & 0 & 0 & 0 & 0 & 0 \\
		\hline
	2 & 0 & 0 & 0 & 0 & 0 & 0 & $-12$ & 9 & 9 & 9 & 12 & 12 \\
		\hline
	3 & 9 & 12 & 12 & $-12$ & 9 & 9 & $-10$ & 0 & 0 & 0 & 0 & 0 \\
		\hline
	4 & $-10$ & 0 & 0 & 0 & 0 & 0 & 9 & 12 & 12 & $-12$ & 9 & 9 \\
		\hline
	\end{tabular}
\end{table}
%\renewcommand{\arraystretch}{1.0}

After including lifting/placing and tilting input we obtain the complete motion vectors $\vec{\mathcal{M}}_i$ for all legs of the robot. 
% The motion vector must be converting into angles for actuators - servos - used in the legs to place the foot of leg into Cartesian system $\left[x,y,z\right]$.
\end{enumerate}

\paragraph{Advanced Crawl} having the $\beta=0.83$ requires an extra attention. It basically follows exactly the same logical sequence however the calculation of component \emph{y} and timing together with \emph{z} is more complicated. \\

\begin{table}[h]
\caption{Relative phase for $\beta=0.83$. The gray cells indicate the non-duty part of the cycle. Dark gray is full non-duty segment, light shade of gray means that a change from duty to non-duty (or vice-versa) is just happening at the given index.}
\label{tab:step83}
\centering
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{l*{12}{p{6pt}}}
	\hline 
	& 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \\
	\hline \hline
	$\varphi_1$ & \cellcolor[gray]{0.85} $\frac{18}{18}$ & \cellcolor[gray]{0.7} $\frac{10}{18}$ & \cellcolor[gray]{0.85} $\frac{4}{18}$ & $\frac{6}{18}$ & $\frac{7}{18}$ & $\frac{8}{18}$ & $\frac{9}{18}$ & $\frac{11}{18}$ & $\frac{13}{18}$ & $\frac{15}{18}$ & $\frac{16}{18}$ & $\frac{17}{18}$ \\
		\hline
		$\varphi_2$ & $\frac{9}{18}$ & $\frac{11}{18}$ & $\frac{13}{18}$ & $\frac{15}{18}$ & $\frac{16}{18}$ & $\frac{17}{18}$ & \cellcolor[gray]{0.85} $\frac{18}{18}$ & \cellcolor[gray]{0.7} $\frac{10}{18}$ & \cellcolor[gray]{0.85} $\frac{4}{18}$ & $\frac{6}{18}$ & $\frac{7}{18}$ & $\frac{8}{18}$ \\
		\hline
		$\varphi_3$ & $\frac{12}{18}$ & $\frac{14}{18}$ & $\frac{16}{18}$ & \cellcolor[gray]{0.85} $\frac{18}{18}$ & \cellcolor[gray]{0.7} $\frac{8}{18}$ & \cellcolor[gray]{0.85} $\frac{2}{18}$ & $\frac{3}{18}$ & $\frac{5}{18}$ & $\frac{7}{18}$ & $\frac{9}{18}$ & $\frac{10}{18}$ & $\frac{11}{18}$ \\
		\hline
		$\varphi_4$ & $\frac{3}{18}$ & $\frac{5}{18}$ & $\frac{7}{18}$ & $\frac{9}{18}$ & $\frac{10}{18}$ & $\frac{11}{18}$ & $\frac{12}{18}$ & $\frac{14}{18}$ & $\frac{16}{18}$ & \cellcolor[gray]{0.85} $\frac{18}{18}$ & \cellcolor[gray]{0.7} $\frac{10}{18}$ & \cellcolor[gray]{0.85} $\frac{2}{18}$ \\
	\end{tabular}
\end{table}
\renewcommand{\arraystretch}{1.0}

\noindent
The table \ref{tab:step83} describes the relative phase withing the cycle for all legs. It again uses 12 stops (0 through 11) and in the contrary to the table \ref{tab:step} it contain sections, where all 4~legs support the robot at time. The transition between stops 2 and 3 is one of the moments, where all 4~legs rest on walking area. The same is true for transitions $5\to6,\:8\to9,\:11\to0$. \\ 

\begin{table}[h]
	\caption{Position of legs depending on the index \emph{k}. The table indicates length of step for all legs depending on the index value}
\label{tab:step83_rev}
\centering
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{|c|c|c|c|c|c|}
	\hline 
	 & \multicolumn{4}{|c|}{relative phase for Leg} & step \\
	\cline{1-5} 
	Index & 1 & 2 & 3 & 4 & incr. \\
	\hline \hline
	0 & $\rfrac{18}{18}$ & $\rfrac{9}{18}$ & $\rfrac{12}{18}$ & $\rfrac{3}{18}$ & \\
	$\vdots$ & \texttiming{ LHL } & & & & +1 \\
	3 & $\rfrac{6}{18}$ & $\rfrac{15}{18}$ & $\rfrac{18}{18}$ & $\rfrac{9}{18}$ & \\
	$\vdots$ & & & \texttiming{ LHL } & & $+\rfrac{1}{2}$ \\
	6 & $\rfrac{9}{18}$ & $\rfrac{18}{18}$ & $\rfrac{3}{18}$ & $\rfrac{12}{18}$ & \\
	$\vdots$ & & \texttiming{ LHL } & & & +1 \\
	9 & $\rfrac{15}{18}$ & $\rfrac{6}{18}$ & $\rfrac{9}{18}$ & $\rfrac{18}{18}$ & \\
	$\vdots$ & & & & \texttiming{ LHL } & $+\rfrac{1}{2}$ \\
	12=0 & $\rfrac{18}{18}$ & $\rfrac{9}{18}$ & $\rfrac{12}{18}$ & $\rfrac{3}{18}$ & \\
	\hline
	\end{tabular}
\end{table}
\renewcommand{\arraystretch}{1.0}

\noindent
There is one more abnormality in the ``$\beta=0.83$ schema''. A varying length of single steps withing a complete stride must be used in order to achieve the cyclic behavior of the walking pattern. In a complete cycle each legs makes two full-length-steps and two half-length-steps. This behavior is clear to detect in the table~\ref{tab:step83}. Looking at the reference leg~4. It starts it first stride-segment at index 0 and it takes thee stops to complete this segment. The length of the corresponding relative trajectory for the first segment (indices 0 though 3) is $\rfrac{6}{18}\equiv\rfrac{1}{3}$, which is the full-length step. The next section starts at the index 3 and takes three stops to complete the second segment. 


\noindent
The length of the corresponding relative trajectory for this second segment (indices 3 though 6) is $\rfrac{3}{18}\equiv\rfrac{1}{6}$, which is the half-length step. This pattern is repeated until the whole cycle gets completed. Table~\ref{tab:step83_rev} shows the same behavior by swapping the axis \emph{x} and \emph{y} in the table. \\
\\
\noindent
Speaking about the duty factor $\beta=0.75$, the entire cycle is divided into 4 equal segments, which is very convenient for a 4-legged-robot. Within the cycle must each leg cover the distance twice as long as the length of step $\Delta$. Each leg covers the full length of step in 3 duty segments of the cycle and again the full length of step in lifted position, when being transferred at the start position again. The normalized ``distance'' between two stops for duty segment is a constant number for all legs. The duty factor $\beta=0.83$, in the contrary, cannot use such a simple model. The problem is that we still have 4 legs only but we need to combine two different modes. First, all 4 legs are supporting the robot within the fraction of a step and second, just three legs support the robot while the fourth is lifted and moved in start position again. That is why we need a non-linear segmenting, combination of short and long steps, plus different length of step for front and hind legs. Considering the three named method a non-linear dependency is tabulated and stored in table~\ref{tab:step83}. \\

\begin{figure}[h]
\centering\includegraphics[width=0.48\textwidth]{83-step-schema.png}
\caption[b]{Profile of a non-duty phase for a leg for duty factor $\beta=0.83$. The figure \emph{a)} shows the trajectory for front leg while the figure \emph{b)} shows the trajectory for hind leg.}  
\label{fig:step83-non-duty}
\end{figure}

\noindent
The figure~\ref{fig:step83-non-duty} shows the profile for non-duty segments. Actually, the non-duty segment is partially a duty segment, as shown in the figure. It is obvious that the full length of step is not utilized for the higher duty factor $\beta=0.83$. The front legs cover just $78\%$ of the length of step while the hind legs cover $89\%$ of the length of step. The duty factor $\beta=0.75$ on the other hand uses linear schema, where each arm is lifted once it reaches relative position 3 and placed back int relative position 0. \\
\\
\noindent
One more aspect must be taken into consideration for the schema with duty factor $\beta=0.83$. The angular velocity of each leg must be adjusted for short and long segment within a step so that the linear velocity of the whole robot remains constant. Just reminding here that the design is using 12 stops to split the cycle. The first 9 stops cover the duty segment, which is part of cycle that affects the movement of the robot. Theoretically, we can use the above outlined schema to calculate the coordinates for the foot of any leg at any position within the Cartesian system. Realistically, we use the quantisation, where the smallest discreet quantum is $\rfrac{\Delta}{9}$. The design must be however able to control the duration of the operation of moving a leg for the $\rfrac{\Delta}{9}$ discreet distance. Only then the linear movement of the whole robot can be kept smooth and constant. The design harnesses linear regression to achieve controlled transition of a foot for the distance $\rfrac{\Delta}{9}$. The linear regression is adequate approximation method to calculate the immediate positions for a foot within two calculated points on a motion vector $\vec{\mathcal{M}}_i$.  

\paragraph{Inverse Kinematics} 
Each leg constitutes of three links (Coxa, Femur, Tibia) and three actuators (Body-Coxa, Coxa-Femur, Femur-Tibia). The first actuator connects the leg to the body. It is a shoulder  

\onecolumn
\begingroup

\begin{figure}
\centering\includegraphics[width=0.87\textwidth]{kinematika_nohy_0.png}
\caption[b]{Model of the leg. The model shows the conversion of the Cartesian system into angles $\alpha,\beta,\gamma$ applied to the actuators in order to place foot of a leg into position $P\left[x,y,z\right]$.}
\label{fig:leg}
\end{figure}

\begin{equation}
\gamma = tan^{-1} \left( \frac{x}{y} \right) 
	\label{equ:conversion_gamma}
\end{equation}
\begin{equation}
\alpha_0 = tan^{-1} \left(\frac{\sqrt{x^2 + y^2} - COXA}{h_0}\right)
	\label{equ:conversion_alpha_0}
\end{equation}
\begin{equation}
	\alpha_1 = cos^{-1} \left(\frac{FEMUR^2 + \left(\sqrt{x^2 + y^2} - COXA\right)^2 + h_0^2 - TIBIA^2}{2\;FEMUR\;\sqrt{\left(\sqrt{x^2+y^2} - COXA\right)^2 + h_0^2}}\right)
	\label{equ:conversion_alpha_1}
\end{equation}
\begin{equation}
	\beta = cos^{-1} \left(\frac{TIBIA^2 + FEMUR^2 - h_0^2 - \left(\sqrt{x^2 + y^2} - COXA\right)^2}{2\;\;FEMUR\;\;TIBIA}\right)
	\label{equ:conversion_beta}
\end{equation}

\noindent
pivot and is referred as $\gamma$. This angle controls the rotation of the whole leg in the plane parallel to the $\left[x,y\right]$ place of the robot's body. The first link is called Coxa, is usually rather short and connects shoulder pivot with the elbow. Another actuator is placed between Coxa and Femur. The angle is called $\alpha$ and allows vertical movement of the leg. The Femur is connected to the Tibia with another actuator. It allows the set the angle between them. The angle is called $\beta$ and operates in vertical plane as well. This angle allows to place the foot near or far to the CoG. Both angles $\alpha,\beta$ operate in the same plane, which is perpendicular to the robot's base plane. All the links in the leg has a fixed length. The actuators connecting the links are standard servos. The output horn of a servo can be set for angle $0-180^\circ$. Therefore a coordinate conversion between $\left[x,y,z\right]$ and angles $\alpha,\beta,\gamma$ must be provided. 

\twocolumn
\endgroup

\newpage

\noindent
The conversion can be based on standard trigonometric functions and law of cosines. 
\noindent
The details of the conversion process are outlined in the figure \ref{fig:leg} and equations \ref{equ:conversion_gamma} though \ref{equ:conversion_beta}.  \\
\\
\noindent
By establishing the conversion mechanism between the Cartesian system of motion vector and angles required by servos used in legs is the chapter of kinematics complete. The next section describes the details of the construction itself. \\

% >>>
\subsection{Mechanical Design}\label{chapter:mechanical_design} % <<<
\begin{figure}[h]
\centering\includegraphics[width=0.33\textwidth]{servo_compartment.png}
\caption[b]{Design of the servo compartment that forms Coxa link.}
\label{fig:servo_compartment}
\end{figure}

\noindent
3\,mm thick plywood was used in this project. The mechanical properties are adequate for the size of the construction. Plywood is rather light material compared to aluminium or plastic, which positively contributes to the overall weight of the construction. The pillars connecting top and bottom plate of the robot are from Nylon (polyamide) rod, having the diameter of 8\,mm. This material is strong enough to allow thread cutting. I used M2 screws to connect the top and bottom plates to the supporting Nylon pillars. The size of the robot was kept as minimal as possible in order to reduce the weight. Low overall weight allows usage of low-budget hobby servos, which will be described in chapter \ref{chapter:servos}. The limiting factors are the size of the main board and the size of the servos used in legs. \\
\\
\noindent
The tool LibreCAD, formerly known as QCAD. This tool provides semi-professional level for technical drawings, is free under GPLv2 license. The drawings were printed out and transferred to the plywood. \\
\\
\noindent
The small mechanical jigsaw was used to cut the parts. The joins were made from a graphic rod revolving in a plywood dry bearing. No classic bearing were necessary, the carbon properties combined with smooth surface of used 2\,mm trick rods were meeting the requirements for this application. The complete construction in shown in the drawing depicted on the page~\pageref{fig:mechanic_overview}, figure~\ref{fig:mechanic_overview}. The black color is used for plywood parts, main board and servos are outlined in blue and mechanical links (servo horns) are violet. The size of the main board exactly fits within the supporting pillars interconnecting the top and bottom plate. \\
\\
\noindent
The details of the leg, showing all the construction parts, are in the figure \ref{fig:arm_detail}. The color-code is identical with the drawing in the picture \ref{fig:mechanic_overview}. The longest part of the leg is Tibia, which is connected to the servo mounts by two screws. This joint between Tibia and Femur forms the servo output shaft only. That installs considerably high shear on the output shaft of the servo. The shear can be minimized by shortening up the distance between the mounting point of tibia on the servo body and the servo horn. The shortest distance can be achieved by mounting the tibia on the top of the servo mounts. The price is however that the rotation angle $\gamma$ must be shifted for certain constant. The reason is that the theoretical model assumes that the projection of the connecting line between tip of tibia  \emph{P} and the output shaft of the shoulder pivot onto the walking plane is perpendicular to the longitudinal axis of the servo casing (top view). 

\onecolumn
\begingroup

\begin{figure}
\centering\includegraphics[width=0.77\textwidth]{arm_detail.png}
\caption[b]{The construction of the leg. Black is plywood, blue color for servos, magenta for servo horns.}
\label{fig:arm_detail}
\end{figure}

\newpage

\begin{figure}
\centering\includegraphics[width=0.97\textwidth]{mechanic_overview_0.png}
\caption[b]{The robot. This figure shows the horizontal projection and profile of the construction. The blue rectangle in the center of the robot's body is the main board.}
\label{fig:mechanic_overview}
\end{figure}

\twocolumn
\endgroup

\noindent
Alternatively an auxiliary pivot can be installed into the servo case opposite to the output shaft for servos on both ends of Femur link and duplicating the Femur itself. This design idea was however not easy to implement with the used low-budget servos (TowerPro 9g), which have very thin and fragile plastic case. My attempt for adding a small pivot made from 2\,mm carbon rod were not mechanically firm enough to support the weight of the construction. Although the output shaft of the used servos is not set in bearings it still provides enough strength to withhold the shear and support the whole construction. I believe the lifetime of servos will be rather short, but it is worth the experiment.\\
\\
\noindent
The same shear forces applies also the servo connecting the Femur with Coxa. The joint is implemented by means of the servo output shaft only. It is the same design pattern as used in the joint between Tibia and Femur. The Coxa itself is very short, corresponding to the width of the servo (11.8\,mm) plus thickness of the plywood (3\,mm). The shoulder servo that rotates the legs in the walking plane. This servo is using the pivot virtually extending the longitudinal axis of the output shaft. The pivot is however not mounted directly in the servo case but an additional plywood buffer layer is used to expand the height of the servo case. This can happen because of the sufficient distance between the top and bottom plate of the robot.   \\
\\
\noindent
The only ``complicated'' part is the servo compartment forming the Coxa link. The shoulder pivot servo and perpendicular servo lifting the Femur are attached together by means of a light weighted compartment made from plywood. The schema and details of the compartment is documented on the figure \ref{fig:servo_compartment}. All parts are glued together by a common 2-component Epoxy. This technique provides sufficient strong links.  \\
\\
\noindent
The plywood parts are blue painted. 

% >>>
\subsection{Actuators}\label{chapter:servos} % <<<
This project uses servos to implement the joints in the legs of the robot. Servos are controlled by sending them a pulse of variable width. The parameters of the pulse is \emph{minimal width}, \emph{maximum width} and \emph{repetition rate}. \\

\begin{figure}[h]
\centering\includegraphics[width=0.48\textwidth]{servo_pwm.png}
\caption[b]{Controlling a servo by a pulse.}
\label{fig:servo_pwm}
\end{figure}

\noindent
Parameters to control a servo are standardized and most of the available servos still uses the same PWM modulation to rotate the output shaft. A typical servo requires a control pulse having the width ranging from $544\mu$s to $2400\mu$s, where $544\mu$s set the servo to the angle position $0^{\circ}$ and $2400\mu$s to the angle position $180^{\circ}$. The $1472\mu$s sets the centered position, $90^{\circ}$, for most servos. Sometimes the $1500\mu$s pulse is used to center the shaft instead. The required repetition rate is usually 20\,ms for most servos. Refer to figure \ref{fig:servo_pwm} for overview.  \\
\\
\noindent
The dependency between the width of the pulse and the angle is linear and thus the equation for ideal servo takes a simple form:

\begin{equation}
		y = 590.87x + 544 
		\label{equ:servo_ideal}
\end{equation}
 
\noindent
Where the input \emph{x} is the angle in radians and output \emph{y} is the width of control pulse in $\mu$s.\\
\\
\noindent
Typical servos are designed for control pulses ranging from $800\mu$s through $2200\mu$s. It means that 0 and 180 degree limits are theoretically not achievable. Sometimes the servo sets the maximal or minimal angle even for shorter width of the pulse and still keeps the dependency linear. Sometime simply the maximum and minimum angle cannot be achieved. Each and every made of servos might behave slightly different way. \\
\\
\noindent
The quadpod design is aware of this limitation and using a corrected equation to determine the angles based on the known control pulses. The experiment for the used servos (9g TowerPro) yielded the equation in this form:

\begin{equation}
		y = 636.4x + 452.4 
		\label{equ:servo_real}
\end{equation}

\noindent
where the units and semantics is identical with the equation \ref{equ:servo_ideal}. Having the linear dependence between the angle of the output shaft and the width of control pulse. The equation \ref{equ:servo_real} is included in the kinematics calculation in the firmware of the robot. 

% >>>
% >>>
\section{Electronics} % <<<
The electronic section gives detail about the IR circuit, servo shield, power sources, controller and main board.  

\subsection{IR Receiver} % <<<
The infrared protocol is used to control the movement of the quadpod. The reception and demodulation is done by a dedicated IC - OS1838, which is budget alternative to Vishal's TSOP31238. The circuit demodulates the incoming IR signal and sends inverted output to the microprocessor. The modulation frequency is 38\,kHz. The signal is intercepted on the external interrupt pin INT0 and the interrupt handler implements a simple finite state machine (FSM) to decode the signal. \\
\\ 
\noindent
The used protocol is Mitsubishi XSat, which has following characteristic: \\

\begin{figure}[h]
\centering\includegraphics[width=0.48\textwidth]{xsattrain.png}
\caption[b]{Train of pulses characteristic for the Mitsubishi XSat Protocol.}
\label{fig:xsattrain}
\end{figure}

%\noindent
%\texttiming{ H [!wscale=\wscale*1.2!] 4H 2L D{C0} D{C1} D{C2} D{C3} D{C4} D{C5} D{C6} D{C7} D{E} 2L D{D0} D{D1} D{D2} D{D3} D{D4} D{D5} D{D6} D{D7} D{E} L } \\

\noindent
where the modulation for logical ``1'' and ``0'' is shown in figure~\ref{fig:xsatmodulation}.

\begin{figure}[h]
\centering\includegraphics[width=0.48\textwidth]{xsatmodulation.png}
\caption[b]{Modulation of the Mitsubishi Protocol.}
\label{fig:xsatmodulation}
\end{figure}

\noindent
The finite state automata for signal decoding is throwing the address away, it decodes the instruction only. An old remote controller was used in this project, presented on the figure~\ref{pic:remote}. The logic analyser ``OpenBench LogicSniffer''  in combination with software ``LogicAnalyser'' was used to identify the IR protocol and interpret the instruction codes send by remote. The finite state automata is delivering just the 8-bit instruction code as a product.  

\begin{figure}[h]
\centering\includegraphics[width=0.36\textwidth]{remote.png}
\caption[b]{Remote control.}
\label{pic:remote}
\end{figure}

% >>>
\subsection{Servo Shield} % <<<
Servo shield is a specialized circuit that drives the multiple servos in parallel. The 4-legged robot is using 3~servos per a single leg and therefore we need a servo shield that drives at least 12~servos in real time. There is variety of commercial servo driver circuits on the market. They are however delivered on a dedicated PCB and typically requires an external step down high current regulator for proper operation of servos. It would mean that three PCBs must be used in the solution, which is way too many. The outlined mechanical design of the robot however allows to place just one small PCB inside the body. The PCB is expected to host power circuits, controller itself and servo shields. A dedicated design is described in this project that satisfies the requirement.\\

\begin{table}[t]
	\caption{Signal model for servo shield}
\begin{tikztimingtable}
Clock & LLh LLLh LLh LLLh LLLh LLh LLLLh LLh LLLh LLLh LLh LLLLh LLh LLLh LLh LLLLh LLh L ;[ dotted ] 2L;\\
B0-RES& HLl LLLl LLl LLLl LLLl LLl LLLLh HHh HHHh HHHh HHh HHHHh HLl LLLl LLl LLLLl LLl L ;[ dotted ] 2L;\\
B1-RES& HHh HHHh HHh HHHh HHHh HHh HHHLl LLl LLLl LLLl LLl LLLLl LLh HHHh HHh HHHHh HHh H ;[ dotted ] 2H;\\
B0-Q1	& LLh HHHl LLl LLLl LLLl LLl LLLLl LLl LLLl LLLl LLl LLLLl LLh HHHl LLl LLLLl LLl L ;[ dotted ] 2L;\\
B0-Q2	& LLl LLLh HHl LLLl LLLl LLl LLLLl LLl LLLl LLLl LLl LLLLl LLl LLLh HHl LLLLl LLl L ;[ dotted ] 2L;\\
B0-Q3	& LLl LLLl LLh HHHl LLLl LLl LLLLl LLl LLLl LLLl LLl LLLLl LLl LLLl LLh HHHHl LLl L ;[ dotted ] 2L;\\
B0-Q4	& LLl LLLl LLl LLLh HHHl LLl LLLLl LLl LLLl LLLl LLl LLLLl LLl LLLl LLl LLLLh HHl L ;[ dotted ] 2L;\\
B0-Q5	& LLl LLLl LLl LLLl LLLh HHl LLLLl LLl LLLl LLLl LLl LLLLl LLl LLLl LLl LLLLl LLh H ;[ dotted ] 2H;\\
B0-Q6	& LLl LLLl LLl LLLl LLLl LLh HHHHl LLl LLLl LLLl LLl LLLLl LLl LLLl LLl LLLLl LLl L ;[ dotted ] 2L;\\
B1-Q1	& LLl LLLl LLl LLLl LLLl LLl LLLLh HHl LLLl LLLl LLl LLLLl LLl LLLl LLl LLLLl LLl L ;[ dotted ] 2L;\\
B1-Q2	& LLl LLLl LLl LLLl LLLl LLl LLLLl LLh HHHl LLLl LLl LLLLl LLl LLLl LLl LLLLl LLl L ;[ dotted ] 2L;\\
B1-Q3	& LLl LLLl LLl LLLl LLLl LLl LLLLl LLl LLLh HHHl LLl LLLLl LLl LLLl LLl LLLLl LLl L ;[ dotted ] 2L;\\
B1-Q4	& LLl LLLl LLl LLLl LLLl LLl LLLLl LLl LLLl LLLh HHl LLLLl LLl LLLl LLl LLLLl LLl L ;[ dotted ] 2L;\\
B1-Q5	& LLl LLLl LLl LLLl LLLl LLl LLLLl LLl LLLl LLLl LLh HHHHl LLl LLLl LLl LLLLl LLl L ;[ dotted ] 2L;\\
B1-Q6	& LLl LLLl LLl LLLl LLLl LLl LLLLl LLl LLLl LLLl LLl LLLLh HHl LLLl LLl LLLLl LLl L ;[ dotted ] 2L;\\
\extracode
	\begin{pgfonlayer}{background}
		\begin{scope}[semitransparent, semithick]
      	\vertlines[gray]{2.1,5.6,8.1,11.6,15.1,17.6,22.1,24.6,28.1,31.6,34.1,38.6,41.1,44.6,47.1,51.6,54.1}
    	\end{scope}
	\end{pgfonlayer}
\end{tikztimingtable}
\label{tab:shield_timing}
\end{table}

\noindent
Johnson decade counter with 10 decoded outputs, available under the code 74HC4017/74HCT4017, delivers a very good match in required functionality. It consists of a 5~D~Flip-flop elements linked together and having additional logic that allows to use the circuit as a ``shift register''. The shift operation happens on rising edge of the clock signal. IC also offers RESET \footnote{Certain versions of Johnson counter requires $\overline{\mbox{RESET}}$ signal to reset the circuit.} signal, which can be used to cascade multiple ICs together is a coordinated manner. This project uses 2~Johnson decade counters as one large shift register to generate the control pulse for 12 servos. The theoretical maximum of two decade counters is actually 18 servos, practically the race hazard may rise for 12 controlled servos already. The point is that the control pulse to a servo may take 2~milliseconds or even more. Having 12 servo connected to the shift register we need more than 24~milliseconds to complete the cycle and start a new one. Strictly speaking, each servo requires the presence of new control pulse within 20\,milliseconds. When the refresh rate drops bellow this rate, the servo may enter a ``fail safe'' condition, which would break the movement. Therefore the practical limit of this design is somewhere between 10 and 14 servos. The assumption is that there is no real position of all legs in which all servos would be preset to $180\degr$. Therefore the race hazard with 12~servos is acceptable for the project.\\
\\
\noindent
The used design requires three output pins on the micro controller to drive both Johnson \\
\\
\noindent
\,\,\, \\ % This is a trick, required for vskip to work.
\vskip 8.60cm
\noindent
counters. One pin delivers common clock signal, two pins control the RESET signal for both counters. The clock signal is actually irregular. The controller is just strobing the CLK pin of both counters with a 2~$\mu$s short pulse. That is long enough for ICs to shift the register. Basically the time delay between two incoming strobes defines the length of a control pulse for one servo. The output pins Q1-Q6 on Johnson counter generates the pulses, whose length is equal to the time delay between two incoming strobes on CLK pin. This simple effect generates the train of pulses required to control servos. The signal generated on Q1-Q6 resembles the control signal from the figure~\ref{fig:servo_pwm}. \\
\\
\noindent
Initially, both counters are reset. Reset condition for the first counter (first bank in shield) is released and shortly after release the first strobe comes. The strobe is shifting the register, which results in high state on Q1 for the first counter. The control pulse is sent to first controller servo. The next strobe on the CLK signal shift the register further, which sets Q1 again to zero and in parallel Q2 goes high. This repeats 6~times. The micro controller releases the reset signal for the second counter and after that resets the first counter after the $6^{th}$ cycle. The reset for first counter is sent together with the strobe pulse and thus acts as terminator for output pulse present on the $6^{th}$~output (Q6) of the first counter. The first counter remains reset and its output pins Q1-Q6 remains in low status. The reset condition for second bank is released well before the strobe comes and therefore the second counter outputs high level on its Q1 pin in the same clock cycle. See table~\ref{tab:shield_timing} for timing details.  \\

% >>>
\subsection{Controller}\label{chapter:controller} % <<<
Initially, the brain of the robot was tested with two models of a 8-bit micro controllers. First Atmel ATMega8/16\,MHz and second Atmel ATMega168/20\,MHz. The final version of the firmware is slightly larger than 8kB and therefore the experiment continued with the second mentioned unit only. The unit corresponds with plenty GIO~pins, though this design requires just three of them to control the servo shield. Additionally the TWI and USART and SPI buses are wired with corresponding connectors on the PCB just in case expansion would be required. The USART bus is used to debug the firmware.

% >>>
\subsection{Power Source} % <<<
The design is using two independent power sources (see the schematic on the figure~\ref{fig:schema}). One power source is used to power up the logic, the second source is powering up servos only. Both power circuits are not galvanic isolated, they share the ground lead in common. Although the servo motors may generate peaks on power line, the experiment did not detect any malfunction of the micro controller and other CMOS based logic. Further description is focused on the power source for servos only. It is built as a linear power source, using 2-stage power amplifier. The power amplifier is formed by resistors R6 through R10, one IC (LM317L) and two transistors, Q2 and Q3. The transistor Q2 is the first stage in the amplifier. I selected BC327-40, a PNP transistor designed for power amplification. It is important to use the version ``BC327-40'', which delivers DC current gain $h_{FE1}=250\sim630$ and $h_{FE2}=170$. The high value of $h_{FE2}$ is important for this application. It delivers enough current into base of Q3, which is the second stage in the amplifier. This transistor is MJE3055, a power transistor capable of handling collector current $\emph{I}_{C}=10A$. The $h_{FE}$ is typically between 20 and 100. This value is meeting the requirement for this application. The output voltage is regulated by adjustable voltage stabilizer, LM317L. The circuit is configured by R9 and R10 to deliver 4.8V under no load or little load only. The LM317L is the only source of current under such conditions. The transistor Q2 opens first after the voltage drop on R7 reaches $\sim0.6V$. This is satisfied once the drawn output current climbs above $\sim6mA$. The Q2 amplification factor starts working and delivers high current into base of Q3. Assuming the back EMF of load is well under the 4.8V the Q3 opens fully and delivers emitter current into load as high as 7-8A. The tests done with the 12~TowerPro servos under load were made. The drawn current was 5-6A. The power transistor MJE3055 requites active cooler while the thermal loses are $\sim$20W. That is rather high value but it is a penalty for using a linear power source.

% >>>
\subsection{Board} % <<<
\begin{figure}[h]
\centering\includegraphics[height=0.42\textwidth, angle=90]{osazovak.png}
\caption[b]{Component layout diagram for the main board, top view.}
\label{fig:osazovak}
\end{figure}
Board was designed in the Eagle 5.12 Light for Linux. The board size is $98\times55\,mm$ and it uses 2 conducting layers. The component layout diagram is the figure~\ref{fig:osazovak}.
% >>>

\onecolumn
\begingroup

\begin{figure}
\centering\includegraphics[height=1.00\textwidth, angle=90]{schema.png}
\caption[b]{Main board schematic}
\label{fig:schema}
\end{figure}

\twocolumn
\endgroup

% >>>
\section{Firmware}\label{chapter:Firmware} % <<<
The firmware is written in C language, compiled with avr-gcc~4.5.3, linked against the AVR Standard C library from the same package. The Standard C library version is 1.8. The Binutils from GNU Toolset (GNU Project) were user to generate the object format flushed into the micro controllers. Tool avrdude was used to transfer the object data into micro controller. The programmer AvrUsb500 from tuxgraphics,org, which is a stk500~V2 compatible programmer. 

\subsection{Fixed Point Mathematics}\label{chapter:fixed_point_math} % <<<
The kinematics of the robot uses trigonometric functions and square root. Originally the firmware linked against the mathematical library from the AVR-GCC Toolchain - libm.a. This increased the size of the firmware drastically and the time required to compute the position for all 4~legs took over 100~ms at 14.7MHz. That introduced a problem because the servos require period close to 20~ms. Therefore optimization techniques were tested to resolve this problem. \\

\paragraph{Linear Regression} is used to approximate the trajectory between two points on the trajectory of a step. As described in the chapter~\ref{chapter:kinematics} each step is divided into 9~discreet segments. The kinematics is calculated for those 9~points only (midpoints of segments) and linear regression is further splitting the discreet segments into smaller sub-segments. The number of those sub-segments defines the smoothness of the movement as well as velocity of the movement. The linear regression is great deal less demanding than the kinematics calculation and we still can position the legs while the kinematics calculation for next discreet segment runs. The linear regression typically uses 7 or 9 points and therefore this optimization might be bringing sufficient margin the complete the kinematics for two subsequent segments. Though the processor will be rather busy with kinematics only and there would be no margin left for other operation. Typically debugging via USART port might get expensive while the USART speed is rather low. \\ 

\paragraph{Fixed point representation} is another tested strategy. The best results were achieved with fixed point representation using 4-bytes-representation, where 2~bytes for integer part and 2~bytes for decimal part. I further found a very compact mathematical library implementing the basic arithmetics for the fixed point numbers plus square root and trigonometric functions. The library is using an interpolation through a cubic function to calculate inverse tangents. The inverse sines and cosines are deduced from inverse tangents. \\
\begin{eqnarray}
	\sin^{-1}(x)=\tan^{-1}\left(\frac{x}{\sqrt{1-x^2}}\right)
	\label{equ:fixpoint_sin} \\
	\cos^{-1}(x)=\rfrac{\pi}{2}-sin^{-1}(x)
	\label{equ:fixpoint_cos}
\end{eqnarray}

\noindent
The square root algorithm is quite directly from wikipedia\footnote{http://en.wikipedia.org/wiki/Methods\_of\_computing\_square\_roots\\\#Binary\_numeral\_system\_.28base\_2.29}. This method consumes less than 8~ms on the same processor to deliver kinematics coordinates for all 4~legs. The precision of calculated angles $\alpha,\beta,\gamma$ is still very good, way better than the precision delivered by the used budget servos TowerPro. \\

\paragraph{CORDIC} method is another technique for calculating the trigonometric functions based on the rotation of a vector. The method is based on the fact that the rotation matrix is built from cos() and sin() trigonometric functions. Rotation of an unit vector then delivers sines and cosines of the angle $\theta$ used inside the rotation matrix. Alternatively, trigonometric function $\tan^{-1}$ is obtained by rotating a vector $\left[1,tan(\theta)\right]$ until the \emph{y} coordinate becomes zero. The idea of CORDIC is expressed in equation~\ref{equ:cordic}. The smart choice of the base angle $\alpha$ helps speed up final algorithm. E.g. $\tan(\alpha_i)=2^{-j}$ for integer number \emph{j} reduces the multiplication to a simple shift operation. The input parameters for the technique were selected based on balance between performance and precision. The delivered data were very good but slightly slower than cubic approximation.

\begin{align}
\begin{split}
	\theta &= \sum_{i=0}^{n} \alpha_i \\
	\begin{bmatrix}
		cos(\theta) & -sin(\theta) \\
		sin(\theta) & cos(\theta)  
	\end{bmatrix} &= \prod_{i=0}^{n} 
	\begin{bmatrix}
		cos(\alpha_i) & -sin(\alpha_i) \\
		sin(\alpha_i) & cos(\alpha_i)  
	\end{bmatrix}
	\label{equ:cordic}
\end{split}
\end{align}

% >>>

% >>>
\onecolumn % <<< Pictures
\begingroup

\begin{figure}[t]
\centering\includegraphics[width=0.92\textwidth]{foto1.png}
\caption[b]{Front-top picture of the quadrupedal}
\label{fig:foto1}
\end{figure}

\begin{figure}[b]
\centering\includegraphics[width=0.92\textwidth]{foto2.png}
\caption[b]{Front picture of the quadrupedal}
\label{fig:foto2}
\end{figure}

\newpage

\begin{figure}[t]
\centering\includegraphics[width=0.90\textwidth]{foto3.png}
\caption[b]{Rear-top picture of the quadrupedal}
\label{fig:foto3}
\end{figure}

\begin{figure}[b]
\centering\includegraphics[width=0.90\textwidth]{foto4.png}
\caption[b]{Leg detail, servo compartment construction.}
\label{fig:foto4}
\end{figure}

\twocolumn
\endgroup

% >>>
%
\begin{thebibliography}{Mm99}
\bibitem{sveden}
\emph{Freyr Hardarson}: Stability analysis and synthesis of statically balanced walking for quadruped robots \\
{\small Royal Institute of Technology, KTH S-100 44 Stockholm, Sweden}

\bibitem{japan}
\emph{Shigeo Hirose, Kan Yoneda, Riki Furuya, Tatsuo Takagi}: Dynamic and static fusion control of quadruped walking vehicle. \\
{\small Tokyo Institute of Technology, Department of mechanical Engineering Science, Japan}

\bibitem{malaysia}
	\emph{S.~Parasuraman, F.J.~Hang and M.K.A.~Ahamed Khan}: Robot Crawler: Statically Balanced Gaits\\
{\small School of Engineering, Monash University, Malaysia}
	
\end{thebibliography}

\end{document}
